<?php
namespace app\web\admin;

use app\common\builder\ZBuilder;
use app\web\model\Traffic as myModel;



/**
 * 职称
 * @package
 */
class Traffic extends Base 
{
    public function index()
    {
        $map = $this->getMap();
        $data_list = myModel::where($map)
                    ->order($this->getOrder("traffic_number desc,id desc"))
                    ->paginate();
        $fields = [
            ['hidden', 'id'],
            ['text', 'traffic_name', '交通名称', '必填'],
            ['number', 'traffic_number', '公里范围(KM)', '必填'],
            ['radio', 'status', '状态', '', ['禁用', '启用'], 1],
        ];
        return ZBuilder::make('table')
            ->setTableName('Traffic')
            ->addColumns([
                ['traffic_name','交通名称'],
                ['traffic_number','公里范围(KM)'],
                ['status','状态','switch'],
                ['right_button', '操作', 'btn']
            ])
            ->setRowList($data_list)
            ->setSearch(['traffic_name' => '交通名称']) // 设置搜索参数
            ->addOrder('traffic_number')
            ->addFilterList('status',['禁用','启用'])
            ->autoAdd($fields,'traffic','Traffic',true)
            ->autoEdit($fields,'traffic','Traffic',true)
            ->addTopButtons(['disable','enable','delete'=>['data-tips' => '删除了就无法恢复了']])
            ->addRightButtons(['delete'=>['data-tips' => '删除了就无法恢复了']])
            ->fetch();
    }
    /**
     * 删除
     * [delete description]
     * @param  array  $record [description]
     * @return [type]         [description]
     */
    public function delete($record = [])
    {
        $ids   = $this->request->isPost() ? input('post.ids/a') : input('param.ids');
        $ids   = (array)$ids;
        myModel::destroy($ids);
        $this->success('操作成功');
    }
}